import {
  reqUserName,
  reqAddUser,
  reqdetele,
  reqRoles,
  reqDoAssign
} from "@/api/username/index";
const state = {
  userList: {},
  QBArrList: [],
};

const mutations = {
  GETUSERLIST: (state, data) => {
    state.userList = data;
  },
  GETUPDATALIST: (state, data) => {
    state.QBArrList = data.allRolesList;
  },
};

const actions = {
  getUserList: async ({ commit }, { pageCurrent, pageSize, userInput }) => {
    let rs = await reqUserName(pageCurrent, pageSize, userInput);
    commit("GETUSERLIST", rs.data);
  },

  getregister: async ({ commit }, { Uname, Nname, Pass }) => {
    let data = {
      username: Uname,
      nickName: Nname,
      password: Pass,
    };
    await reqAddUser(data);
  },
  deldeteHandle: async ({ commit }, id) => {
    await reqdetele(id);
  },
  getUpdate: async ({ commit }, row) => {
    await reqAddUser(row);
  },
  getUpdataList: async ({ commit }, id) => {
    let rs = await reqRoles(id);
    rs.data.allRolesList.forEach((item) => {
      item.xz = false;
      rs.data.assignRoles.forEach((val) => {
        if (item.id == val.id) {
          item.xz = true;
        }
      });
    });
    commit("GETUPDATALIST", rs.data);
  },

  getDoAssign:async({commit},{userId,roleId})=>{
    await reqDoAssign(userId,roleId)
  }



};
const getters = {};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
};
